home *** CD-ROM | disk | FTP | other *** search
- Path: news.production.compuserve.com!news
- From: Terry Nikkel <102101.2325@CompuServe.COM>
- Newsgroups: comp.lang.c++
- Subject: Help needed: reference parameter
- Date: 27 Feb 1996 15:17:41 GMT
- Organization: SACDA, Inc.
- Message-ID: <4gv7al$o0c$1@mhafc.production.compuserve.com>
-
- I am posting this for a colleague, thanks for your help:
- I want to pass a reference (default 0) parameter to a function.
- For example, assume classes 'AClass' and 'BClass'; assume
- 'AClass' has a method called 'Function'.
-
- //AClass.hxx
- #include "BClass.hxx"
- bool AClass::Function (BClass& = 0); // would be the
- specification
-
- //AClass.cxx
- bool AClass::Function (BClass& refer) // is the actual method
- {
- if (! (refer == 0) {
- ...
- {
- }
-
- The problem is the specification does not work. To accommodate
- the above I have a constructor for BClass that takes an int
- (BClass(const int) {} ), as well as operator==(const int).
- I would have thought this was enough, but the compiler errors
- with the message "initial value of reference to non-const has
- incorrect type" on "BClass& = 0);". What am I doing wrong?
- Terry Nikkel: email terry.l.nikkel@ontario.honeywell.com
-
- --
- Terry Nikkel
- Information Specialist
- SACDA, Inc., London, Ontario N6B 1V5
- tnikkel@p01.on49.honeywell.com
-